define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'work/commission/index' + location.search,
                    //add_url: 'work/commission/add',
                    edit_url: 'work/commission/edit',
                    del_url: 'work/commission/del',
                    multi_url: 'work/commission/multi',
                    import_url: 'work/commission/import',
                    table: 'work_commission',
                }
            });

            var table = $("#table");
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                //这里我们手动设置底部的值
                    $('label[for="warranty.id"]').parent().css('display','none'); // 隐藏描述查询栏
            });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate:false},
                        {field: 'warranty.workID', title: __('warranty.workID')},
                        {field: 'hospital.name', title: __('hospital.name')},
                        {field: 'equipment.name', title: __('equipment.name'), operate:'like'},
                        {field: 'equipment.serial', title: __('equipment.serial')},
                        {field: 'type_data', title: __('Type_data'), searchList: {"0":__('Type_data 0'),"1":__('Type_data 1')}, formatter: Table.api.formatter.normal},
                        {field: 'user.nickname', title: __('员工'), operate:'like'},
                        {field: 'achievement', title: __('Achievement'), operate:false},
                        {field: 'commission', title: __('Commission'), operate:false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'grant_data', title: __('Grant_data'), searchList: {"0":__('Grant_data 0'),"1":__('Grant_data 1')}, formatter: Table.api.formatter.normal},
                        {field: 'warranty.id', title: __('工单Id'), operate: '=',visible:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
            // 初始化表格参数配置
            Table.api.init({
                search: false,
                showToggle: false,
                pagination: true,
                showColumns: false,
                showExport: false,
                extend: {
                    "index_url": "work/commission"+ location.search,
                    "add_url": "",
                    "edit_url": "",
                    "del_url": "",
                    "multi_url": "",
                }
            });
            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'achievement', title: __('业绩')},
                        {field: 'commission', title: __('提成')},
                        {field: 'type_data', title: __('Type_data'), searchList: {"0":__('Type_data 0'),"1":__('Type_data 1')}, formatter: Table.api.formatter.normal},
                        {field: 'user.nickname', title: __('员工')},
                        {field: 'grant_data', title: __('Grant_data'), searchList: {"0":__('Grant_data 0'),"1":__('Grant_data 1')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                    ]
                ],
                commonSearch: false
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
            $(document).on('click', "#btn_query", function () {
                //var id=$("#id_value").val();
                var opt = {
                    url: $.fn.bootstrapTable.defaults.extend.index_url,
                };
                table.bootstrapTable('refresh',opt);
                return false;
            });
            $(document).on('click', ".btn-refresh", function () {
                //var id=$("#id_value").val();
                var opt = {
                    url: $.fn.bootstrapTable.defaults.extend.index_url,
                };
                table.bootstrapTable('refresh',opt);
                return false;
            });
            $(document).on("fa.event.appendfieldlist", "#add-form .btn-append", function (e, obj) {
                //绑定动态下拉组件
                Form.events.selectpage(obj);
            });
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});